﻿using System;
using System.Globalization;
using System.Windows.Data;
using StockholmsStad.Runtime.Serialization.DataContract;
using StockholmsStad.Runtime.Serialization.DataContract.Enums;
using StockholmsStad.Utilities;

namespace StockholmsStad.Windows.UI.Infrastructure.Converters
{
    public class CeremonyTypeToValueIdConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(object))
                throw new InvalidOperationException("The target must be a boolean");

            if(value != null)
            {
                var type = (CeremonyType) Enum.ToObject(typeof (CeremonyType), value);

                var valueType = new ValueIdPair
                           {
                               Id = (int) type,
                               Name = Enum.GetName(typeof (CeremonyType), value),
                               Description = EnumUtility.GetEnumDescription((CeremonyType)value)
                           };

                return valueType;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
